#pragma once
#ifndef _LIST_TIMER_
#define _LIST_TIMER_

#include "ClientData.hpp"
#include <time.h>
#include <memory>
#include <functional>

class util_time
{
public:
    util_time():prev(nullptr),next(nullptr) {}
public:
    time_t exprie;
    std::function<void (std::shared_ptr<ClientData>)> cb_func;
    std::shared_ptr<ClientData> user_data;
    std::shared_ptr<util_time> prev;
    std::shared_ptr<util_time> next;
};

class sort_timer_list
{
public:
    void add_timer(std::shared_ptr<util_time> timer);
    void adjust_timer(std::shared_ptr<util_time> timer);
    void del_timer(std::shared_ptr<util_time> timer);
    void tick(void);
public:
    const std::shared_ptr<util_time> GetHead() const { return head;}
private:
    void add_timer(std::shared_ptr<util_time> timer,std::shared_ptr<util_time> last_head);
private:
    std::shared_ptr<util_time> head;
    std::shared_ptr<util_time> tail;
};

#endif // _LIST_TIMER_